package com.dt.common.validation.parser;

import java.lang.reflect.Field;

import com.alibaba.fastjson.JSONObject;
import com.dt.common.validation.annotation.NotBlank;
import com.dt.common.validation.definition.NotBlankDefinition;
import com.dt.common.validation.impl.DefaultValidationDefinition;
import com.dt.common.validation.itf.PropertyGetter;

public class NotBlankDefinitionParser extends DefinitionParser {

	@Override
	public DefaultValidationDefinition parseFromAnnotation(Field field, PropertyGetter propertyGetter) {
		NotBlank notBlank = field.getAnnotation(NotBlank.class);
		if (notBlank != null) {
			NotBlankDefinition definition = new NotBlankDefinition();
			definition.setRawMsg(notBlank.msg());

			return definition;
		}
		return null;
	}

	@Override
	public DefaultValidationDefinition parseFromJson(JSONObject metaValues) {
		NotBlankDefinition definition = new NotBlankDefinition();
		definition.setRawMsg(this.getMsgDefinition(metaValues, true));
		return definition;
	}

}
